package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.AppCategoryBasedataExCode;
import com.handydata.antifraud.bo.appcategorybasedata.AppCategoryBasedataReqBO;
import com.handydata.antifraud.bo.appcategorybasedata.AppCategoryBasedataResBO;
import com.handydata.antifraud.vo.appcategorybasedata.CreateAppCategoryBasedataReqVO;
import com.handydata.antifraud.vo.appcategorybasedata.CreateAppCategoryBasedataResVO;
import com.handydata.antifraud.vo.appcategorybasedata.DeleteAppCategoryBasedataReqVO;
import com.handydata.antifraud.vo.appcategorybasedata.DeleteAppCategoryBasedataResVO;
import com.handydata.antifraud.vo.appcategorybasedata.ModifyAppCategoryBasedataReqVO;
import com.handydata.antifraud.vo.appcategorybasedata.ModifyAppCategoryBasedataResVO;
import com.handydata.antifraud.vo.appcategorybasedata.AppCategoryBasedataBeanVO;
import com.handydata.antifraud.vo.appcategorybasedata.QueryAppCategoryBasedataReqVO;
import com.handydata.antifraud.vo.appcategorybasedata.QueryAppCategoryBasedataResVO;
import com.handydata.antifraud.service.AppCategoryBasedataService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/appcategorybasedata")
@RestController
public class AppCategoryBasedataController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(AppCategoryBasedataController.class);
	
	@Autowired
	private AppCategoryBasedataService appCategoryBasedataService;
	
	@ApiOperation(value="新增app类别码表", notes="新增app类别码表")
	@ApiImplicitParam(name = "req", value = "新增app类别码表请求对象", required = true, dataType = "CreateAppCategoryBasedataReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateAppCategoryBasedataResVO createAppCategoryBasedata(@RequestBody CreateAppCategoryBasedataReqVO req) {
		try {
			logger.info("Execute createAppCategoryBasedata, param is {}", req);
			AppCategoryBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppCategoryBasedataReqBO.class);
			AppCategoryBasedataResBO resBO = appCategoryBasedataService.createAppCategoryBasedata(reqBO);
			CreateAppCategoryBasedataResVO res = CommonBeanConvertor.convert(resBO, CreateAppCategoryBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateAppCategoryBasedataResVO.class, req, AppCategoryBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改app类别码表", notes="修改app类别码表")
	@ApiImplicitParam(name = "req", value = "修改app类别码表请求对象", required = true, dataType = "ModifyAppCategoryBasedataReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyAppCategoryBasedataResVO modifyAppCategoryBasedata(@RequestBody ModifyAppCategoryBasedataReqVO req) {
		try {
			logger.info("Execute modifyAppCategoryBasedata, param is {}", req);
			AppCategoryBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppCategoryBasedataReqBO.class);
			AppCategoryBasedataResBO resBO = appCategoryBasedataService.modifyAppCategoryBasedata(reqBO);
			ModifyAppCategoryBasedataResVO res = CommonBeanConvertor.convert(resBO, ModifyAppCategoryBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyAppCategoryBasedataResVO.class, req, AppCategoryBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除app类别码表", notes="删除app类别码表")
	@ApiImplicitParam(name = "req", value = "修改app类别码表请求对象", required = true, dataType = "DeleteAppCategoryBasedataReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteAppCategoryBasedataResVO deleteAppCategoryBasedata(@RequestBody DeleteAppCategoryBasedataReqVO req) {
		try {
			logger.info("Execute deleteAppCategoryBasedata, param is {}", req);
			AppCategoryBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppCategoryBasedataReqBO.class);
			AppCategoryBasedataResBO resBO = appCategoryBasedataService.deleteAppCategoryBasedata(reqBO);
			DeleteAppCategoryBasedataResVO res = CommonBeanConvertor.convert(resBO, DeleteAppCategoryBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteAppCategoryBasedataResVO.class, req, AppCategoryBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询app类别码表", notes="查询app类别码表")
	@ApiImplicitParam(name = "req", value = "查询app类别码表请求对象", required = true, dataType = "QueryAppCategoryBasedataReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryAppCategoryBasedataResVO queryAppCategoryBasedata(@RequestBody QueryAppCategoryBasedataReqVO req) {
		try {
			logger.info("Execute queryAppCategoryBasedata, param is {}", req);
			AppCategoryBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppCategoryBasedataReqBO.class);
			AppCategoryBasedataResBO resBO = appCategoryBasedataService.queryAppCategoryBasedata(reqBO);
			QueryAppCategoryBasedataResVO res = CommonBeanConvertor.convert(resBO, QueryAppCategoryBasedataResVO.class, AppCategoryBasedataBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryAppCategoryBasedataResVO.class, req, AppCategoryBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
